package com.huatai.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.common.util.StringUtil;
import com.huatai.manage.entity.TbTrialModelEntity;
import com.huatai.manage.mapper.TbTrialLabelMapper;
import com.huatai.manage.entity.TbTrialLabelEntity;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.service.TbTrialLabelService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 标签管理;(TbLabelManage)表服务实现类
 *
 * @author luoxc
 * @since 2023-03-14 14:13:39
 */
@Service("tbLabelManageService")
public class TbTrialLabelServiceImpl extends ServiceImpl<TbTrialLabelMapper, TbTrialLabelEntity> implements TbTrialLabelService {

	/**
	 * 根据标签id获取信息
	 * @param labelId
	 * @return
	 */
	@Override
	public TbTrialLabelEntity getByLabelId(String labelId) {
		return getOne(Wrappers.<TbTrialLabelEntity>lambdaQuery().eq(TbTrialLabelEntity::getLabelId, labelId));
	}

	/**
	 * 根据标签id集合删除信息
	 * @param labelIds
	 * @return
	 */
	@Override
	public boolean removes(List<String> labelIds) {
		if(labelIds.isEmpty()) return false;
		return remove(Wrappers.<TbTrialLabelEntity>lambdaQuery().in(TbTrialLabelEntity::getLabelId, labelIds));
	}

	/**
	 * 分页获取标签列表
	 * @param pageQuery
	 * @return
	 */
	@Override
	public Page<TbTrialLabelEntity> pageList(PageQuery<TbTrialLabelEntity> pageQuery) {
		Page<TbTrialLabelEntity> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
		String labelName = pageQuery.getData().getLabelName();
		String labelType = pageQuery.getData().getLabelType();
		LambdaQueryWrapper<TbTrialLabelEntity> wrapper = Wrappers.<TbTrialLabelEntity>lambdaQuery()
			.eq(StringUtil.isNotBlank(labelType), TbTrialLabelEntity::getLabelType, labelType)
			.like(StringUtil.isNotBlank(labelName), TbTrialLabelEntity::getLabelName, labelName);
		return page(page, wrapper);
	}

	/**
	 * 根据标签id修改标签信息
	 * @param tbTrialLabelEntity
	 * @return
	 */
	@Override
	public boolean update(TbTrialLabelEntity tbTrialLabelEntity) {
		LambdaQueryWrapper<TbTrialLabelEntity> wrapper = Wrappers.<TbTrialLabelEntity>lambdaQuery();
		wrapper.eq(TbTrialLabelEntity::getLabelId, tbTrialLabelEntity.getLabelId());
		return update(tbTrialLabelEntity, wrapper);
	}

	/**
	 * 判断数据是否存在
	 *
	 * @param labelId
	 * @return
	 */
	@Override
	public boolean isExist(String labelId) {
		long count =
			this.count(Wrappers.<TbTrialLabelEntity>lambdaQuery().eq(TbTrialLabelEntity::getLabelId, labelId));
		return count > 0;
	}
}

